<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('审定成本结算')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<style>
    input::-webkit-outer-spin-button,
    input::-webkit-inner-spin-button {
        -webkit-appearance: none;
    }

    input[type="number"] {
        -moz-appearance: textfield;
    }
</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-settlement-approval">
        <input id="id" name="id" type="hidden" th:value="${settlement.id}"/>
        <input id="isFiled" name="isFiled" type="hidden" th:value="${settlement.isFiled}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">编号：</label>
            <div class="col-sm-8">
                <input type="hidden" id="billNo" th:value="${settlement.billNo}"/>
                <input class="form-control" type="text" id="billNo" placeholder="请输入编号"
                       th:value="${settlement.billNo}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">项目名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" id="proName" placeholder="请输入项目名称"
                       th:value="${settlement.proName}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">工程公司：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" id="compName" th:value="${settlement.compName}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商务经理：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" id="businessManager" placeholder="请输入商务经理"
                       th:value="${settlement.businessManager}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">审核内容：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" id="auditContent" placeholder="请输入审核内容"
                       th:value="${settlement.auditContent}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">分包班组信息：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" id="teamInfo" placeholder="请输入分包班组信息"
                       th:value="${settlement.teamInfo}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">申请金额：</label>
            <div class="col-sm-8">
                <input class="form-control" type="number" id="applyMoney" placeholder="请输入申请金额"
                       th:value="${settlement.applyMoney}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">结算审定金额：</label>
            <div class="col-sm-8">
                <input class="form-control" type="number" name="settlementMoney" placeholder="请输入结算审定金额"
                       th:value="${settlement.settlementMoney}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">核减原因：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="reduceReason" placeholder="请输入核减原因"
                       th:value="${settlement.reduceReason}">
            </div>
        </div>
        <div class="form-group" id="finalMoney">
            <label class="col-sm-3 control-label is-required">终审金额：</label>
            <div class="col-sm-8">
                <input class="form-control" type="number" name="finalMoney" placeholder="请输入终审金额"
                       onblur="compute()" th:value="${settlement.finalMoney}" required>
            </div>
        </div>
        <div class="form-group" id="reduceMoney">
            <label class="col-sm-3 control-label is-required">核减值：</label>
            <div class="col-sm-8">
                <input class="form-control" type="number" name="reduceMoney" placeholder="请输入核减值"
                       th:value="${settlement.reduceMoney}">
            </div>
        </div>
        <div class="form-group" id="reduceRate">
            <label class="col-sm-3 control-label is-required">核减率(%)：</label>
            <div class="col-sm-8">
                <input class="form-control" type="number" name="reduceRate" placeholder="请输入核减率"
                       th:value="${settlement.reduceRate}">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    var prefix = ctx + "costSettlement";

    $(function () {
        if ($("#isFiled").val() == 2) {
            $("input[name='settlementMoney']").attr("readOnly", true);
            $("input[name='reduceReason']").attr("readOnly", true);
            $("#reduceMoney").show();
            $("#reduceRate").show();
            $("#finalMoney").show();
        } else {
            $("#reduceMoney").hide();
            $("#reduceRate").hide();
            $("#finalMoney").hide();
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-settlement-approval").serializeArray();
            $.operate.save(prefix + "/approval", data);
        }
    }

    function compute() {
        $("input[name='reduceMoney']").val($("#applyMoney").val() - $("input[name='finalMoney']").val());
        $("input[name='reduceRate']").val(Number($("input[name='reduceMoney']").val() / $("#applyMoney").val() * 100).toFixed(2))
    }

</script>
</body>
</html>